package com.company;

public class 回文子串 {
    static int ret = 0;
    public static int getLongestPalindrome(String A, int n) {
        // write code here
        // 特判
        if (A == null || n == 0) return ret;
        for (int i = 0; i < n - 1; i++) {
            helper(A, i, i); // 以i为中心，向两边扩散
            helper(A, i, i + 1); // 以i和i+1为中心，向两边扩散
        }
        return ret;
    }
    public static void helper(String s, int left, int right) {
        while (left >= 0 && right < s.length() && s.charAt(left) == s.charAt(right)) {
            left -= 1;
            right += 1;
        }
        ret = Math.max(ret, right - left - 1);
    }

    public static void main(String[] args) {
        System.out.println(getLongestPalindrome("test123321test","test123321test".length()));
    }
}
